package core
{
	import interfaces.IAction;
	import interfaces.IMsgListener;
	
	public class ActionManager implements IMsgListener
	{
		private static var ACTION_LIST:Vector.<IAction>;
		private var m_tempList:Vector.<IAction>;
		
		public function ActionManager()
		{
			ACTION_LIST = new Vector.<IAction>();
		}
		
		public function msgManager(e:*=null):void
		{
		}
		
		// 更新
		public function update():void
		{
			if(ACTION_LIST.length <= 0)return;
			for(var i:int = 0; i < ACTION_LIST.length; i++)
			{
				if(ACTION_LIST[i].start)
					ACTION_LIST[i].update();
				else
				{
					deleteAction(ACTION_LIST[i]);
					i--;
				}
			}
		}
		
		// 注册动画到动画元件列表
		public function addAction(a:IAction):void
		{
			for(var i:int =  0; i < ACTION_LIST.length; i++)
			{
				if(ACTION_LIST[i] == a)return;
			}
			a.start = true;
			ACTION_LIST.push(a);
		}
		
		// 注销动画from 动画列表
		public function deleteAction(a:IAction):void
		{
			for(var i:int =  0; i < ACTION_LIST.length; i++)
			{
				if(ACTION_LIST[i] == a)
				{
					ACTION_LIST.splice(i,1);
					break;						
				}
				
			}
		}
		
		// 清除所有动画
		public function clearAllAction():void
		{
			while(ACTION_LIST.length > 0)
			{
				deleteAction(ACTION_LIST.shift());
			}
		}
		
		// 暂停动画
		public function pauseAllAction(b:Boolean):void
		{
			for(var i:int =  0; i < ACTION_LIST.length; i++)
			{
				ACTION_LIST[i].pause = b;
			}
		}
	}
}